import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;

public class Output {
    public ArrayList<String> ls;
    public Output(ArrayList<String> ls){
        this.ls=ls;
    }
    //定义一个输出函数，参数为输出地址outputAddress
    public void output(String outputAddress){
        //定义一个FileWriter对象fw，置空
        FileWriter fw = null;
        try {
            //尝试建立输出地址对应的文件，赋值给fw
            fw = new FileWriter(outputAddress);
        } catch (IOException e) {
            e.printStackTrace();
        }
        //建立文件输出流bw，由FileWriter fw输出给bw
        BufferedWriter bw=new BufferedWriter(fw);

        for(int i=0;i<ls.size();i++){

            try {
                //将ls中的第i个元素写入输出流，即写入目标文件
                bw.write(ls.get(i));
                //在输出流中换行
                bw.newLine();
            } catch (IOException e) {
                e.printStackTrace();
            }

        }
        try {
            //关闭输出流
            bw.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}